<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<% 
String path=request.getContextPath(); 
String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; 
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<base href="<%=basePath%>">
<title>协议配置</title>
<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>

<style type="text/css">
		#detail
        {
            position:relative;
            width: 200px;
            font-size: 12px;
            background: #fff;
            border: 1px solid #000;
            z-index: 2;
            display: none;
        } 
        #detail2
        {
            position:relative;
            width: 200px;
            font-size: 12px;
            background: #fff;
            border: 1px solid #000;
            z-index: 2;
            display: none;
        } 
	.input_fxk {width: 15px;height: 15px;}
</style>
<script type="text/javascript">
	var startP = 1; //1 代表当前页，主页面默认展示第1页
	//权限归属机构默认值
	var defaultBranch;
	
	$(document).ready(function() {
		
		$.ajax({
			url : "<%=path%>/noCarProtocol/queryPrivilegeBranch?"+new Date().getTime(),
			type : 'POST',
			async : false,
			dataType:'json',
			success : function(result) {
				if(result){
					if($.validate(result))return;
					var data = result.data;
					if(data.length > 0){
						defaultBranch = data[0].deptCode;
						for (var i = 0; i < data.length; i++) {
							 $("#changeDept").append("<option value="+data[i].deptCode+">"+data[i].deptCname+"</option>");
						}
					}
				}
			}
		});
		//初始读取数据 
		loadInsuPlan({changeDept:defaultBranch});
		
		<%if(null!=request.getAttribute("flag")){
		if("edittrue".equals(request.getAttribute("flag").toString())){
		%>	
			$.message("success","修改成功");
		<%}
		if("addtrue".equals(request.getAttribute("flag").toString())){
		%>
			$.message("success","添加成功");
		<%}}%>
		
		
	});
	
	//绑定单选按钮事件，选中某个单选按钮，该按钮所在行高亮显示
	function bindradio(){
		$("input[name='radioInsuplan']").click(function(){
			$("input[name='radioInsuplan']").parent().parent().removeClass("table_highlighter");
			$(this).parent().parent().addClass("table_highlighter");
       	});
		$("input[name='partnerradio']").click(function(){
			$("input[name='partnerradio']").parent().parent().removeClass("table_highlighter");
			$(this).parent().parent().addClass("table_highlighter");
       	});
	}

	//为查询协议拼接参数 queryInsuPlan  queryProtocol queryInsuPlan
	function queryInsuPlan(displayPage){
		var protocolNo=$('#protocolNo').val();
		var planName=$('#planName').val();
		//归属机构2位机构id
		var changeDept=$('#changeDept').val();
		var tbrName=$('#tbrName').val();
		var bbrName=$('#bbrName').val();
		var protocol_type=$('#protocol_type').val();
		var startDate=$('#startDate').val();
		var endDate=$('#endDate').val();
		if(null != startDate && "" != startDate){
			var str = "";
			var strReg = "[0-9]{4}-[0-9]{2}-[0-9]{2}";
			if(startDate.match(strReg)==null){
				$.message("error", "您输入的协议开始日期格式不正确，格式为:YYYY-MM-DD");
				return;
			}
		}
		if(null != endDate && "" != endDate){
			var str = "";
			var strReg = "[0-9]{4}-[0-9]{2}-[0-9]{2}";
			if(endDate.match(strReg)==null){
				$.message("error", "您输入的协议结束日期格式不正确，格式为:YYYY-MM-DD");
				return;
			}
		}
		
		loadInsuPlan({current:displayPage,size:10,protocolNo:protocolNo,planName:planName,changeDept:changeDept,tbrName:tbrName,bbrName:bbrName,protocol_type:protocol_type,startDate:startDate,endDate:endDate});
	}
	
	//加载协议
	function loadInsuPlan(param){
		$.openLoading();
			$.ajax({
					url : "<%=path%>/noCarProtocol/queryTradProtocolValuePage",
					type : 'POST',
					async : false,
					dataType:'json',
					data:param,
					success : function(page) {
						$.closeLoading();
						if($.validate(page))return;
							startP = page.current;
							var firstbutton ="<input class='input_fxk' name='radioInsuplan' type='radio' value='#'>";
							var lastbutton = "<a href='javascript:void(0)' onClick='edit(this);return false'>编辑</a>&nbsp;<a href='javascript:void(0)' onClick='warnDelProtocol(this);return false'>删除</a>";
							var tableContent = creatTable1("PROTOCOL_NO,PRTL_START_DATE,prodType@TDH,PRTL_END_DATE,TBR_NAME,BBR_NAME,dept_cname",page,firstbutton,lastbutton);
							
							var tableObj = $("#InsuProtocolTable");
							tableObj.find("tbody").remove();
							tableObj.append(tableContent);
							var strPage = creatChannelPage(startP,6,page.maxPage,"15");
							var pageDIV = $("#InsuProtocolPageDIV");
							pageDIV[0].innerHTML="";
							
							pageDIV.append(strPage);
							
							bindradio();//点击单选按钮，该行高亮显示
					}
				});
		}
	
	
//删除协议前弹出提示框
function warnDelProtocol(obj){
	$.dialog({
		type: "warn",
		content: "您确定要删除该协议吗？",
		onOk: function() {
			delProtocol(obj);
		}
	});
}
//删除协议
function delProtocol(obj){
	$.openLoading();
	var delTr = $(obj).parent('td').parent('tr')[0];
	var protocol_no = delTr.childNodes[1].innerHTML;
	$.ajax({
		url: "<%=path%>/noCarProtocol/delTradProtocolValue",
		type: "post",
		dataType: "json",
		data:{protocol_no:protocol_no},
		async:true,
		cache:false,
		success: function(data) {
			$.closeLoading();
			if("success"==data.result && ""!= data.message){
				queryInsuPlan(1);
			}else if("error"==data.result && ""!= data.message){
				$.message("error", data.message);
			}
		}
	});
}
	
//跳转至协议编页面并展示协议信息
function edit(obj){
	var delTr = $(obj).parent('td').parent('tr')[0];
	var protocol_no = delTr.childNodes[1].innerHTML;
	
	window.location.href='<%=path%>/noCarProtocol/edit?protocol_no='+encodeURIComponent(encodeURIComponent(protocol_no));
}
	
//跳转至添加协议页面
function add(){
	window.location.href='<%=path%>/noCarProtocol/add';
}

//点击”重置“，清空查询条件
function clearParams(){
	$('#protocolNo').val('');
	$('#planName').val('');
	$('#changeDept').val(defaultBranch);
	$('#tbrName').val('');
	$('#bbrName').val('');
	$('#protocol_type').val('');
	$('#startDate').val('');
	$('#endDate').val('');
}

//点击协议详情
function detailses(){
	var radioss=$("input[name='radioInsuplan']:checked");
	if(radioss.length==0){
		$.message("error", "请先选择一条协议");
		return;
	}
	var detailsTr=$("input[name='radioInsuplan']:checked").parent('td').parent('tr')[0]; 
	var details_protocol_no = detailsTr.childNodes[1].innerHTML;
	
	$.openLoading();
	$.ajax({
		url:"noCarProtocol/loadByprotocol_no",
		type:'POST',
		data:{protocol_no:details_protocol_no},
		dataType:'json',
		success:function(data){
			$.closeLoading();
			$("#protocol_no_div").html(data.PROTOCOL_NO);
			$("#businessScope_div").html(data.BUSI_SCOPE_NAME); 
			$("#ex_dept_div").html(data.EX_DEPT);
			$("#startDate_div").html(data.PRTL_START_DATE);
			$("#endDate_div").html(data.PRTL_END_DATE);
			$("#bbr_type_div").html(data.BBR_TYPE_NAME);
			$("#tbr_name_div").html(data.TBR_NAME);
			$("#tbr_addr_div").html(data.TBR_ADDR);
			$("#tbr_tel_div").html(data.TBR_TEL);
			$("#bbr_name_div").html(data.BBR_NAME);
			$("#bbr_addr_div").html(data.BBR_ADDR);
			$("#bbr_tel_div").html(data.BBR_TEL);
			$("#ex_scope_div").html(data.EX_SCOPE);
			$("#ex_warrprid_div").html(data.EX_WARRPRID+"个月");
			$("#max_mileage_div").html(data.MAX_MILEAGE+"公里");
			$("#vender_warranty_period_div").html(data.VENDER_WARRANTY_PERIOD+"个月");
			$("#vender_warranty_mileage_div").html(data.VENDER_WARRANTY_MILEAGE+"公里");
			$("#vehicle_use_property_div").html(data.VEHICLE_USE_PROPERTY);
			$("#id_type_div").html(data.ID_TYPE_NAME);
			$("#id_no_div").html(data.ID_NO);
			$("#business_license_no_div").html(data.BUSINESS_LICENSE_NO);
			$("#market_expense_ratio_div").html(data.MARKET_EXPENSE_RATIO);
			$("#money_laundering_risk_div").html(data.MONEY_LAUNDERING_RISK_NAME);
			$("#channelCodeQD_div").html(data.CHANNEL_CODE);
			$("#channelType_div").html(data.CHANNEL_TYPE);
			$("#bsnsType_div").html(data.NEW_BSNS_TYPE);
			$("#deptCode_div").html(data.DEPT_CODE);
			$("#empName_div").html(data.EMP_NO);
			$("#teamName_div").html(data.TEAM_CODE);
			$("#serviceCode_div").html(data.SERVICE_CODE);
			$("#agentNo_div").html(data.AGENT_NO);
			$("#protocolNo_div").html(data.PROTOCOL_NO1);
			$("#specialArran_div").val(data.SPECIAL_ARRAN);
			$("#is_pool").html(data.IS_POOL);
			//打开协议详情<div>
			$("#protocol_Div").OpenDiv();
		}
		 					
	});
	
}
//关闭协议详情<div>
function closeProtocol_Div(){
	$("#protocol_Div").CloseDiv();
}

function exportProtocolMessage(){
	var protocolNo=$('#protocolNo').val();
	var planName=$('#planName').val();
	//归属机构2位机构id
	var changeDept=$('#changeDept').val();
	var tbrName=$('#tbrName').val();
	var bbrName=$('#bbrName').val();
	var protocolType=$('#protocol_type').val();
	var startDate=$('#startDate').val();
	var endDate=$('#endDate').val();
	if(null != startDate && "" != startDate){
		var str = "";
		var strReg = "[0-9]{4}-[0-9]{2}-[0-9]{2}";
		if(startDate.match(strReg)==null){
			$.message("error", "您输入的协议开始日期格式不正确，格式为:YYYY-MM-DD");
			return;
		}
	}
	if(null != endDate && "" != endDate){
		var str = "";
		var strReg = "[0-9]{4}-[0-9]{2}-[0-9]{2}";
		if(endDate.match(strReg)==null){
			$.message("error", "您输入的协议结束日期格式不正确，格式为:YYYY-MM-DD");
			return;
		}
	}
	$("#protocolNoHD").val(protocolNo);
	$("#planNameHD").val(planName);
	$("#changeDeptHD").val(changeDept);
	$("#tbrNameHD").val(tbrName);
	$("#bbrNameHD").val(bbrName);
	$("#protocolTypeHD").val(protocolType);
	$("#startDateHD").val(startDate);
	$("#endDateHD").val(endDate);
	$.dialog({
		type: "warn",
		content: "您确定要导出协议详情吗？",
		onOk: function() {
			document.form1.action= "<%=path%>/noCarProtocol/exportProtocolMessage";
		    document.form1.submit();
		}
	});
}
</script>
</head>
<body>
<form method="POST" name="form1">
	<input type="hidden" name="protocolNo" id="protocolNoHD">
	<input type="hidden" name="planName" id="planNameHD">
	<input type="hidden" name="changeDept" id="changeDeptHD">
	<input type="hidden" name="tbrName" id="tbrNameHD">
	<input type="hidden" name="bbrName" id="bbrNameHD">
	<input type="hidden" name="protocolType" id="protocolTypeHD">
	<input type="hidden" name="startDate" id="startDateHD">
	<input type="hidden" name="endDate" id="endDateHD">
</form>
<div class="current">
           <table class="current_table_1">
              <tbody>
                <tr class="f2">
                  <td>
                    <img src="./images/current_1.jpg">
                  </td>
                  <td class="current_table_1_td">
                    <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                      <span style=" color:#136bab; ">财险产品管理
                      <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>协议配置
                  </span>
                  </td>
                  <td><img src="./images/current_3.jpg"></td>
              </tr>
           </tbody>
         </table>
      </div>
	<table class="table_02" id="table" >
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td width="32%" height="30">
								<div style="display: inline-block;">
									协议编号：
									&nbsp;&nbsp;<input name="protocolNo" id="protocolNo"  type="text" class="input_text" value="" >
								</div>
							</td>
							<td width="23%" height="30">方案名称：
								&nbsp;&nbsp;<input name="planName" id="planName"  type="text" class="input_text" value="" >
							</td>
							<td width="40%" height="30">归属机构：
								<select id="changeDept"  class="select_1 valid" style="visibility: visible;"></select>
							</td>
							</tr>
							<tr height="30px">
							<td width="23%" height="30">投保人名称：
						 		&nbsp;<input name="tbrName" id="tbrName"  type="text" class="input_text" value="" >
							</td>
							<td width="30%" height="30">被保人名称：
								&nbsp;<input name="bbrName" id="bbrName"  type="text"  class="input_text" value="" >
							</td>
							<td width="30%" height="30">协议类型：
								<select id="protocol_type" onchange="" class="select_1 valid" style="visibility: visible;">
		                  		<option value="">-----请选择-----</option>
		                  		<option value="CJB">车捷保延保协议</option>
		                  </select>
							</td>
							</tr>
							<tr height="30px">
							<td width="30%" height="30">协议开始日期：
								<input id="startDate" onkeydown="false" onclick="showCalendar('startDate','y-mm-dd');" class="input_time" type="text" />
							</td>
							<td width="30%" height="30">协议结束日期：
								<input id="endDate" onkeydown="false" onclick="showCalendar('endDate','y-mm-dd');" class="input_time" type="text" />
							</td>
							</tr>
							<tr height="30px">
							<td></td>
							<td width="15%" height="30" style="text-align: center;">
								<input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryInsuPlan(1)"/>&nbsp;
								<input type="button" value="重置" onClick="clearParams()" class="input_button_1" />							
							</td>
							<td></td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td width="100%" height="30">
								<input type="button"  class="input_button_2" id="searchBtn" value="新增协议" onClick="add()"/>
								&nbsp;<input type="button"  class="input_button_2" id="detailsBtn" value="协议详情" onClick="detailses()"/>
								 &nbsp;<input type="button"  class="input_button_2" id="searchBtn" value="导出协议详情" onClick="exportProtocolMessage()"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="InsuProtocolTable"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:16%">延保协议编号</th>
			                  <th style="width:8%">协议开始日期</th>
			                  <th style="width:8%">协议结束日期</th>
			                  <th style="width:12%">投保人姓名</th>
			                  <th style="width:12%">被保人姓名</th>
			                  <th style="width:30%">归属机构</th>
			                  <th style="width:8%">操作</th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="InsuProtocolPageDIV"  class="page"></div>
				</td>
			</tr>
		</table>
<!------------------------------------------------协议详情页面   默认为隐藏------------------------------------ -->
		<div id="protocol_Div"  style="display:none;width:90%;height:80%;top:50px;">
			<div class="table_title_div">
				<table class="table_title" style='width:100%;height: 20px;'>
					<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="/manager/images/closedown.gif" alt="关闭"  onClick="closeProtocol_Div()"/></td>
					</tr>
				</table>
			</div>
			<div style="height:380px;overflow-y: scroll">
			<table class="table_05">
		              <tr>   
		                  <td width="12%" style="text-align:right">延保协议编号：</td>
		                  <td width="20%" id="protocol_no_div"></td>
		              	  <td width="13%" style="text-align:right">业务范围 ：</td>
		              	  <td width="18%" id="businessScope_div"></td>
		              	  <td width="17%" style="text-align:right">
		              	            第三方延保服务机构：
		              	  </td>
		              	  <td width="20%" id="ex_dept_div"></td>	
		              </tr>
		              <tr>
		                  <td style="text-align:right">
		                  	协议开始日期：
		                  </td>
		                  <td id="startDate_div"></td>
		                  <td style="text-align:right">协议结束日期：</td>
		                  <td id="endDate_div"></td>
		                  <td style="text-align:right">被保人类型：</td>
		                  <td id="bbr_type_div"></td>
		              </tr>
		              <tr>
		              	  <td style="text-align:right">投保人姓名：</td>
		              	  <td id="tbr_name_div"></td>
		                  <td style="text-align:right">投保人地址：</td>
		                  <td id="tbr_addr_div"> </td>
		                  <td style="text-align:right">投保人电话：</td>
		                  <td id="tbr_tel_div"></td>
		              </tr>
		              <tr>
		                  <td style="text-align:right">被保人姓名：</td>
		                  <td id="bbr_name_div"></td> 
		                  <td style="text-align:right">被保人地址：</td>
		                  <td id="bbr_addr_div"> </td>
		                  <td style="text-align:right">被保人电话：</td>
		                  <td id="bbr_tel_div"></td>
		              </tr>
		              <tr>
		                  <td style="text-align:right">延保保障范围：</td>
		                  <td id="ex_scope_div"></td>
		                  <td style="text-align:right">延保保修期限：</td>
		                  <td id="ex_warrprid_div"></td>
		                  <td style="text-align:right">保修期限-总里程：(质保里程+延保里程)</td>
		                  <td id="max_mileage_div"></td>
		              </tr>
		              <tr>
		                  <td style="text-align:right">厂家质保期限：</td>
		                  <td id="vender_warranty_period_div"></td>
		                  <td style="text-align:right">厂家质保里程数：</td>
		                  <td id="vender_warranty_mileage_div"></td>
		                  <td style="text-align:right">车辆使用性质：</td>
		                  <td id="vehicle_use_property_div"></td>
		              </tr>
		              <tr>
		                  <td style="text-align:right">证件类型：</td>
		                  <td id="id_type_div"></td>
		                  <td style="text-align:right">有效身份证明号：</td>
		                  <td id="id_no_div"></td>
		                  <td style="text-align:right">经营许可证号：</td>
		                  <td id="business_license_no_div"></td>
		              </tr>
		              <tr>
		                  <td style="text-align:right">市场费用率：</td>
		                  <td id="market_expense_ratio_div"></td>
		                  <td style="text-align:right">洗钱风险：</td>
		                  <td id="money_laundering_risk_div"></td>
		                  <td style="text-align:right">是否共保：</td>
		                  <td id="is_pool"></td>
		                  
		              </tr>
		              <tr>
		                  <td style="text-align:right">归属渠道：</td>
		                  <td id="channelCodeQD_div"></td>
		                  <td style="text-align:right">渠道类型：</td>
		                  <td id="channelType_div"></td>
		                  <td style="text-align:right">业务来源：</td>
		                  <td id="bsnsType_div"></td>
		              </tr>
		              <tr>
		                  <td style="text-align:right">机构部门：</td>
		                  <td id="deptCode_div"></td>
		                  <td style="text-align:right">业务员：</td>
		                  <td id="empName_div"></td>
		                  <td style="text-align:right">销售团队：</td>
		                  <td id="teamName_div"></td>
		              </tr>
		              <tr>
		                  <td style="text-align:right">服务代码：</td>
		                  <td id="serviceCode_div"></td>
		                  <td style="text-align:right">代理人编码：</td>
		                  <td id="agentNo_div"></td>
		                  <td style="text-align:right">合作协议号：</td>
		                  <td id="protocolNo_div"></td>
		              </tr>
		              <tr>
		                  <td style="text-align:right">固定特别约定：</td>
		                  <td colspan="5">
		                  	<textarea name="specialArran_div" id="specialArran_div" cols="" rows="5" class="textarea_1" readonly="readonly" style="border:0px;background-color:#f6f7f9;width:100%"></textarea>
		                  </td>
	              	  </tr>
	         </table>
	       </div>
		</div>

</body>
</html>